package com.ruoyi.web.controller.bookstore;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookstore.domain.BorrowBooks;
import com.ruoyi.bookstore.service.IBorrowBooksService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 借书记录Controller
 * 
 * @author ruoyi
 * @date 2022-07-20
 */
@RestController
@RequestMapping("/bookstore/borrowBooks")
public class BorrowBooksController extends BaseController
{
    @Autowired
    private IBorrowBooksService borrowBooksService;

    /**
     * 查询借书记录列表
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:list')")
    @GetMapping("/list")
    public TableDataInfo list(BorrowBooks borrowBooks)
    {
        startPage();
        List<BorrowBooks> list = borrowBooksService.selectBorrowBooksList(borrowBooks);
        return getDataTable(list);
    }

    /**
     * 导出借书记录列表
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:export')")
    @Log(title = "借书记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BorrowBooks borrowBooks)
    {
        List<BorrowBooks> list = borrowBooksService.selectBorrowBooksList(borrowBooks);
        ExcelUtil<BorrowBooks> util = new ExcelUtil<BorrowBooks>(BorrowBooks.class);
        util.exportExcel(response, list, "借书记录数据");
    }

    /**
     * 获取借书记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(borrowBooksService.selectBorrowBooksById(id));
    }

    /**
     * 新增借书记录
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:add')")
    @Log(title = "借书记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BorrowBooks borrowBooks)
    {
        return toAjax(borrowBooksService.insertBorrowBooks(borrowBooks));
    }

    /**
     * 修改借书记录
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:edit')")
    @Log(title = "借书记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BorrowBooks borrowBooks)
    {
        return toAjax(borrowBooksService.updateBorrowBooks(borrowBooks));
    }

    /**
     * 删除借书记录
     */
    @PreAuthorize("@ss.hasPermi('bookstore:borrowBooks:remove')")
    @Log(title = "借书记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(borrowBooksService.deleteBorrowBooksByIds(ids));
    }
}
